package com.xx.springboot.test.RabbitMQ;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * decr:
 * create by Xiaoxi
 * email:xiaoxiunique@qq.com
 * phone:13541863172
 * date:2018/8/30/030 9:58
 * project_name:SpringBoot-MybatisPlus
 * package_name:com.xx.springboot.test.RabbitMQ
 */
public class RabbitMQUtil {

    /**
     * 创建一个连接
     * @return
     * @throws IOException
     * @throws TimeoutException
     */
    public static Connection getConnection() throws IOException, TimeoutException {

        // 定义一个连接工厂
        ConnectionFactory factory = new ConnectionFactory();

        // 设置服务地址
        factory.setHost("127.0.0.1");

        // 设置AMQP 协议通讯端口
        factory.setPort(5672);

        // 设置 vhost 数据库名称
        factory.setVirtualHost("/rabbit_test");

        // 设置用户名
        factory.setUsername("xiaoxi");

        // 设置密码
        factory.setPassword("xiaoxi");


        return factory.newConnection();
    }
}
